package com.hong.kafka;


import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

/**
 * @author: csh
 * @Date: 2021/3/25 13:58
 * @Description:kafka生产者
 */
public class MyKafkaProducer {
    public static void main(String[] args) {
        Properties props = new Properties();
        props.put("bootstrap.servers", "localhost:9092,localhost:9093,localhost:9094");
        props.put("acks", "all");
        props.put("retries", 0);
        props.put("batch.size", 16384);
        props.put("linger.ms", 1);
        props.put("buffer.memory", 33554432);
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

        Producer <String, String> producer = new KafkaProducer<String,String>(props);
        for (int i = 0; i < 1000; i++){
            producer.send(new ProducerRecord <String, String>("hong3", Integer.toString(i), "发送的值是:"+Integer.toString(i)));
        }
        producer.close();
    }

}
